#include "LPC11xx.h"
#include "utilfun.h"
#include "gpio.h"
#include "network.h"
#include "api_stiio.h"

/***************************************************************
 * Macro definitions                                           *
 ***************************************************************/

/***************************************************************
 * Globol variables                                            *
 ***************************************************************/

/***************************************************************
 * Functions                                                   *
 ***************************************************************/
void myDelay (uint32_t ulTime)
{
    uint32_t i;

    i = 0;
    while (ulTime--) {
        for (i = 0; i < 5000; i++);
    }
}

void halDataReceived(uint8_t * data, uint32_t len)
{
    uint32_t tmp;
    tmp = ((uint32_t)data[1] << 8) + data[2];
    if (tmp < 0x8000) {
        tmp >>= 7;  // get positive integer.
    }
    else {
        tmp = 0;
    }
    printf("%02x: T, %03dC L, %c\n", data[0], tmp, data[3]?'Y':'N');
    
    printf("waiting for data...\n");
}

/***************************************************************
 * MAIN                                                        *
 ***************************************************************/
int main (void)
{
    SystemInit();             /* MUST BE INCLUDED! */
    
    utilInit();
    
    networkInit(0x00, 0);
    networkSetIntCallback(halDataReceived);
    
    StiInit();
    MyStdout=LCD;
    
    printf("waiting for data...\n");
    
    while (1) {
        networkProcessDuty();
    }
}

/***************************************************************
 * END OF FILE                                                 *
 ***************************************************************/
